package ice;

import com.guo.util.ResourceUtil;
import ice.adaptor.HelloServerAdaptor;

/***
 * ICE 服务
 * @author wangqingguo
 * @date 2018/4/1
 */
public class Server extends com.zeroc.Ice.Application {
    /***
     * 启动ICE服务
     * @param args .
     * @return int
     */
    @Override
    public int run(String[] args) {
        if (args.length > 0) {
            System.err.println(appName() + ": too many arguments");
            return 1;
        }
        System.out.println("创建server适配器，Hello");
        com.zeroc.Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello");

        // 配置topicName   客户端使用 hello：tcp -p 10000
        System.out.println("创建topicName:hello，监听端口10000...");
        System.out.println("为接口创建servant...");
        adapter.add(new HelloServerAdaptor(), com.zeroc.Ice.Util.stringToIdentity("hello"));

        System.out.println("激活适配器，服务器等待处理请求...");
        adapter.activate();
        communicator().waitForShutdown();
        return 0;
    }

    public static void main(String[] args) {
        String serverConfigPath = ResourceUtil.getResourcePath("/ice/config.server");
        Server app = new Server();
        int status = app.main("Server", args, serverConfigPath);
        System.exit(status);
    }
}
